package com.example.myBatis.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.boot.autoconfigure.security.SecurityProperties;

import java.util.List;
@Mapper
public interface UserInfoMapper {
    //方法的实现
    @Select("select*from userInfo")
    //方法的声明
    List<UserInfo> selectAll();
//企业开发，尽量不要用*,如果需要全量的字段，都写一遍
    @Select("select *from userInfo where id=#{id131}")
    UserInfo selectOne(Integer id);
    @Select("select*from userInfo where id=#{userId}")
    //只有一个参数，你就算不去重命名也是可以滴
    UserInfo selectOne2(Integer id);

    @Select("select *from userinfo where username='${username}'")
     List<UserInfo>selectByName1(String username);


    @Select("select * from userinfo where username=#{ username }")
    UserInfo selectByName(String username);
    @Select("select*from userInfo ")
        //只有一个参数，你就算不去重命名也是可以滴
    List<UserInfo> selectOne3();
   // @Select("select *from userInfo")

    //返回自增id
   @Options(useGeneratedKeys = true,keyProperty ="id")
    @Insert("insert into userinfo (username,password,age,gender,phone)" +
            "values(#{username},#{password},#{age},#{gender},#{phone})")
    Integer insert( UserInfo userInfo);

//对Insert对参数进行重命名
@Options(useGeneratedKeys=true,keyProperty ="id")
@Insert("insert into userinfo (username,password,age,gender,phone)" +
        "values(#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender},#{userInfo.phone})")
Integer insert2(@Param("userInfo") UserInfo userInfo);
//删除数据库内容
@Delete("delete from userInfo where id=#{id}")
    Integer delete(Integer id);
//修改数据库内容
@Update("update userInfo set age=#{age} where id=#{id}")
    Integer update(UserInfo userInfo);
//排序
@Select("select * from userinfo order by id ${sort}")
    List<UserInfo>selectUserBySort(String sort);

@Select("select *from userinfo where username like '%${username}%'")
List<UserInfo> selectUserBylike(String username);

//@ResultMap(value = "BaseMap")
    @Select("select *from userinfo where username=#{username}")
    List<UserInfo>selectByName8(String username);
}
